import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
const resolvePath = (str: string) => path.resolve(__dirname, str);
//1、按需导入组件
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";

//2、按需导入样式
import { createStyleImportPlugin, ElementPlusResolve } from 'vite-plugin-style-import'; //按需导入样式，AndDesignVueResolve, VantResolve,
//createStyleImportPlugin({ // 按需导入样式，自定义组件库样式
//  libs: [
//    {
//      libraryName: 'my-custom-library',
//      esModule: true,
//      resolveStyle: (name) => {
//        return `my-custom-library/es/${name}/style/index`;
//      },
//    },
//  ],
//}),

export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()], // 自动导入 Element Plus API
      // imports: ["vue", "vue-router"], // 自动导入 Vue 和 Vue Router 的 API
      // dts: true, // 生成类型声明文件
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    createStyleImportPlugin({
      resolves: [ElementPlusResolve()],
    }),
  ],
  resolve: {
    alias: {
      "@": resolvePath("./src"),
      "@components": resolvePath("./src/components"),
      "@assets": resolvePath("./src/assets"),
      "@utils": resolvePath("./src/utils"),
    },
  },
});
